
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>SpringBoot中如何实现异步处理？ - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>SpringBoot中如何实现异步处理？ - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">配置</div>
          <div class="card-question">在 Spring Boot 中，应使用哪个注解来启用异步方法执行功能？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">配置</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">应该在配置类上添加 `@EnableAsync` 注解，该注解可以启用 Spring 的异步方法执行功能。</div>
          </div>
          <div class="card-source">来源: 1. 配置异步支持</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">如何将一个普通方法改造为异步执行方法，以避免阻塞主线程？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">在需要异步执行的方法上添加 `@Async` 注解。添加后，该方法将在一个单独的线程中运行，而不会阻塞调用它的线程。</div>
          </div>
          <div class="card-source">来源: 2. 使用 @Async 注解实现异步方法</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">当一个异步方法没有明确指定线程池时，它默认会使用什么来执行？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">默认情况下，`@Async` 注解使用的是 Spring 提供的默认线程池。</div>
          </div>
          <div class="card-source">来源: 3. 自定义线程池</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">配置</div>
          <div class="card-question">如何为 Spring 的异步任务自定义一个线程池，并让特定 `@Async` 方法使用它？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">配置</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">首先，在配置类中定义一个 `Executor` 类型的 Bean（例如 `ThreadPoolTaskExecutor`）。然后，在 `@Async` 注解中通过传入该 Bean 的名称来指定使用此线程池，例如 `@Async("taskExecutor")`。</div>
          </div>
          <div class="card-source">来源: 3. 自定义线程池</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">Spring 的异步方法支持哪些类型的返回值，以便调用方能获取任务的执行结果？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">异步方法可以返回 `Future`、`CompletableFuture` 或 `ListenableFuture`，以便在任务完成后获取结果。</div>
          </div>
          <div class="card-source">来源: 4. 返回值处理</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">当一个 `@Async` 方法需要返回结果时，文档中展示了如何使用 `Future` 接口的实现类来包装返回值？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">文档示例中使用了 `AsyncResult<>` 类来包装异步任务的返回结果，例如 `return new AsyncResult<>("任务完成");`。</div>
          </div>
          <div class="card-source">来源: 4. 返回值处理</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">如何为 Spring 异步任务配置一个全局的未捕获异常处理器？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">可以通过让配置类实现 `AsyncConfigurer` 接口，并重写 `getAsyncUncaughtExceptionHandler()` 方法来返回一个自定义的 `AsyncUncaughtExceptionHandler` 实例，从而处理异步方法中未被捕获的异常。</div>
          </div>
          <div class="card-source">来源: 5. 异常处理</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">在 Spring Boot 中应用异步处理（@Async）能带来哪些主要好处？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">异步处理允许任务在单独线程中执行而不阻塞主线程，从而提高应用程序的性能、响应速度和吞吐量，特别适用于耗时操作或并发任务场景。</div>
          </div>
          <div class="card-source">来源: 文档开篇段落</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">配置</div>
          <div class="card-question">在自定义 `ThreadPoolTaskExecutor` 作为异步任务执行器时，文档示例中配置了哪些核心参数？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">配置</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">文档示例中配置了核心线程数 (`CorePoolSize`)、最大线程数 (`MaxPoolSize`)、队列容量 (`QueueCapacity`) 以及线程名前缀 (`ThreadNamePrefix`)。</div>
          </div>
          <div class="card-source">来源: 3. 自定义线程池</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
